package com.qiantu.phone.ui.shotview;

import android.content.Context;

import com.qiantu.phone.R;
import com.qiantu.phone.widget.RoundSeekBar;

import static com.qiantu.phone.ui.uiutil.LLDeviceUtil.LIGHT;
import static com.qiantu.phone.ui.uiutil.LLDeviceUtil.POWER;
import static com.qiantu.phone.ui.uiutil.LLDeviceUtil.POWER_OFF;
import static com.qiantu.phone.ui.uiutil.LLDeviceUtil.POWER_ON;

/**
 * @ClassName DimmingLightShotView
 * @Description TODO
 * @Author ShiJunqiang
 * @Date 2021/12/10 16:15
 * @Version 1.0
 */
public class DimmingLightShotView extends BaseDeviceActView {
    private RoundSeekBar roundSeekBar;

    public DimmingLightShotView(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.dimming_shot_view;
    }

    @Override
    public void initView() {
        roundSeekBar = findViewById(R.id.round_seek_bar);
        roundSeekBar.setOnChangeListener(new RoundSeekBar.OnChangeListener(){

            @Override
            public void onProgressChanged(int value) {

            }

            @Override
            public void onStopTrackingTouch(int value) {
                if(value == 0){
                    addAct(POWER, POWER_OFF);
                    removeAct(LIGHT);
                }else{
                    addAct(POWER, POWER_ON);
                    addAct(LIGHT, value + "");
                }
            }

            @Override
            public void onSwitch(boolean isOpen) {
                if(isOpen){
                    addAct(POWER, POWER_ON);
                    if(roundSeekBar.getProgress() != 0){
                        addAct(LIGHT, roundSeekBar.getProgress() + "");
                    }else{
                        removeAct(LIGHT);
                    }
                }else{
                    addAct(POWER, POWER_OFF);
                    removeAct(LIGHT);
                }
            }
        });
    }

    @Override
    public void updateView() {
        //默认空的话，添加默认动作开
        if(mDeviceActMap.size() == 0){
            addAct(POWER, POWER_ON);
        }
        //根据已保存动作指令集合更新UI
        roundSeekBar.setOpenState(POWER_ON.equals(getState(POWER, "0")));
        roundSeekBar.setProgress(Integer.valueOf(getState(LIGHT, "0")));
    }
}
